﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
using XLua;
[LuaCallCSharp]
public class Game
{
    //更改物体名字
    public static void ChangeName(GameObject game, string name)
    {
        game.name = name;
    }
    //创建一个空物体
    public static GameObject CreateGame(GameObject parent)
    {
        GameObject obj = new GameObject();
        return GameObject.Instantiate(obj, parent.transform);
    }
    //删除物体
    public static void DestoryGame(GameObject game)
    {
        GameObject.Destroy(game);
    }
    //根据索引获得子物体
    public static GameObject GetChildByIndex(GameObject parent, int index)
    {
        return parent.transform.GetChild(index).gameObject;
    }
    //得到子物体
    public static GameObject GetChild(GameObject parent, string path)
    {
        if (path == null)
        {
            return parent;
        }
        else
        {
            return parent.transform.Find(path).gameObject;
        }
    }
    //设置点击事件
    public static void SetOnClick(GameObject obj, string path, UnityAction action)
    {
        GetChild(obj, path).GetComponent<Button>().onClick.RemoveAllListeners();
        GetChild(obj, path).GetComponent<Button>().onClick.AddListener(action);

    }
    //设置ui大小
    public static void SetRectSize(GameObject gameObject, int x, int y)
    {
        RectTransform rect = gameObject.GetComponent<RectTransform>();
        rect.sizeDelta = new Vector2(x, y);
    }
    //得到当前屏幕分辨率
    public static void GetScreen(ref int x, ref int y)
    {
        x = Screen.width;
        y = Screen.height;
    }
    //得到UI总结点
    public static GameObject GetGameUI()
    {
        return GameObject.Find("GameUI");
    }
    //卸载一个资源包
    public static void UnLoadAsset(string abName)
    {
        AssetBundleManager.UnLoadAssetBundle(abName);
    }
    //加载一个资源包
    public static void LoadAsset(string abName)
    {
        AssetBundleManager.LoadAssetBundle(abName);
    }
    //加载一个Prefab到节点下
    public static GameObject LoadPrefab(string abName, string path, GameObject parent)
    {
        GameObject assets = AssetBundleManager.LoadAsset<GameObject>(abName, path);
        return GameObject.Instantiate(assets, parent.transform);
    }
}
